package com.oa.ylms.apps.business.archives.impl;

import java.util.List;

import com.oa.ylms.apps.business.archives.IRPCategoryService;
import com.oa.ylms.apps.constants.IDEDStates;
import com.oa.ylms.apps.dao.archives.IRPCategoryDao;
import com.oa.ylms.apps.entity.archives.RPCategoryValue;

public class RPCategoryServiceImpl implements IRPCategoryService {
	private IRPCategoryDao categoryDao;
	private RPCategoryValue rpCategory;

	@Override
	public int addRPCategory(String categoryName, int isRP) throws Exception {
		rpCategory.setCategoryName(categoryName);
		rpCategory.setIsRP(isRP);
		rpCategory.setStates(IDEDStates.ENABLE);
		return categoryDao.addRPCategory(rpCategory);
	}

	@Override
	public boolean deleteRPCategory(int categoryId) throws Exception {
		rpCategory = queryByCategoryId(categoryId);
		if(rpCategory != null){
			rpCategory.setStates(IDEDStates.DELETE);
			categoryDao.editRPCategory(rpCategory);
		}
		return false;
	}

	@Override
	public boolean modifyRPCategory(int categoryId, String categoryName) throws Exception {
		rpCategory = queryByCategoryId(categoryId);
		if(rpCategory != null){
			rpCategory.setCategoryName(categoryName);
			categoryDao.editRPCategory(rpCategory);
		}
		return false;
	}

	@Override
	public RPCategoryValue queryByCategoryId(int categoryId) throws Exception {
		rpCategory.setCategoryId(categoryId);
		return categoryDao.queryByCategoryId(rpCategory);
	}

	@Override
	public List<RPCategoryValue> queryRPCategory(Integer isRP, Integer states)
			throws Exception {
		rpCategory.setIsRP(isRP);
		rpCategory.setStates(states);
		return categoryDao.queryRPCategory(rpCategory);
	}

	@Override
	public boolean toDisable(int categoryId) throws Exception {
		rpCategory = queryByCategoryId(categoryId);
		if(rpCategory != null){
			rpCategory.setStates(IDEDStates.DISABLE);
			categoryDao.editRPCategory(rpCategory);
		}
		return false;
	}

	@Override
	public boolean toEnable(int categoryId) throws Exception {
		rpCategory = queryByCategoryId(categoryId);
		if(rpCategory != null){
			rpCategory.setStates(IDEDStates.ENABLE);
			categoryDao.editRPCategory(rpCategory);
		}
		return false;
	}
	
	public IRPCategoryDao getCategoryDao() {
		return categoryDao;
	}

	public void setCategoryDao(IRPCategoryDao categoryDao) {
		this.categoryDao = categoryDao;
	}

	public RPCategoryValue getRpCategory() {
		return rpCategory;
	}

	public void setRpCategory(RPCategoryValue rpCategory) {
		this.rpCategory = rpCategory;
	}

}
